package com.example.demo.controller;

import com.example.demo.entity.*;
import com.example.demo.service.QuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
public class QuanController {
    @Autowired
    private QuanService quanService;

    @GetMapping("getlist5")
    @ResponseBody
    public MyResult getlist(QuanxianVo quanxianVo) {
        if (quanxianVo.getPage() == 0) {
            quanxianVo.setPage(1);
        }
        int b = (quanxianVo.getPage() - 1) * quanxianVo.getLimit();
        quanxianVo.setB(b);
        Map<String, Object> map = new HashMap<>();
        List<Quanxian> getpage = quanService.getpage5(quanxianVo);
        Integer getcount = quanService.getcount5(quanxianVo);

        MyResult result = new MyResult(0, "注册成功！", getcount, getpage);
//        map.put("code", 0);
//        map.put("msg", "注册成功！");
//        map.put("count", getcount);
//        map.put("data", getpage);
        return result;
    }

    @GetMapping("/Bydelete5")
    @ResponseBody
    public Map<String, Object> Bydelete(Integer[] ids) {
        Map<String, Object> map = new HashMap<>();
        Integer re = null;
//        for (Integer i: ids) {
        re = quanService.Bydelete5(ids);
//        }
        map.put("code", 0);
        map.put("msg", "请求成功！");
        map.put("count", 1);
        map.put("data", re);
        return map;
    }


    @PostMapping("/insert5")
    @ResponseBody
    public Map<String,Object> insert5(Quanxian quanxian){
        Map<String, Object> map = new HashMap<>();
        Integer integer = quanService.insert5(quanxian);
        map.put("code", 0);
        map.put("msg", "请求成功！");
        map.put("count", 1);
        map.put("data", integer);
        return map;
    }



    @GetMapping("/getquan")
    @ResponseBody
    public Map<String, Object> getquan(Quanxian quanxian) {
        Map<String, Object> map = new HashMap<>();
        List<Quanxian> getquan = quanService.getquan(quanxian);
        map.put("code", 0);
        map.put("msg", "请求成功！");
        map.put("count", 1);
        map.put("data", getquan);
        return map;
    }
}
